package com.synnex.mobile.servier.core.resource.dao.impl;

import com.synnex.mobile.generic.dao.impl.GenericHibernateDaoImpl;
import com.synnex.mobile.servier.core.contact.dto.Contact;
import com.synnex.mobile.servier.core.resource.dao.ResourceDao;
import com.synnex.mobile.servier.core.resource.dto.Resource;
import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-8-12
 * Time: 下午8:39
 * To change this template use File | Settings | File Templates.
 */
public class ResourceDaoImpl  extends GenericHibernateDaoImpl<Resource, Integer> implements ResourceDao{

    public List<Resource> ListResource(String key) {
        Criteria c = this.getSession().createCriteria(Resource.class);

        if(key!=null && !"".equals(key)){
            c.add(Restrictions.like("name", key, MatchMode.ANYWHERE));
        }
        c.addOrder(Order.asc("seq"));
        return c.list();
    }

    public void addResource(Resource record) {
        super.save(record);
    }

    public void editResource(Resource record) {
        super.update(record);
    }

    public Resource getResourceById(Integer id) {
        return super.get(id);
    }

    public void deleteResourceById(Integer id) {
        super.delete(super.get(id));
    }
}
